package com.n4v1.pko.server.network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import com.n4v1.pko.server.model.actor.Character;

public class NetHandler implements Runnable {
	
	private Socket socket;
	private Character c;
	private BufferedReader in = null;
    private PrintWriter out = null;
    private Thread t1, t2;
    
	public NetHandler(Socket socket, Character c) {
		super();
		this.socket = socket;
		this.c = c;
	}

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			out = new PrintWriter(socket.getOutputStream());
			t1 = new Thread(new NetReader(in, c));
			t1.start();
			t2 = new Thread(new NetWriter(out));
			t2.start();
		} catch (IOException e) {
			System.err.println(c.getLogin() + " is now offline.");
		}
	}

}
